package com.appinfo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.appinfo.base.BaseService;
import com.appinfo.dao.AppInfoDao;
import com.appinfo.entity.AppInfo;
import com.appinfo.entity.AppVersion;
import com.appinfo.entity.vo.AppInfoSearchVo;
import com.appinfo.util.Page;

@Service
public class AppInfoService extends BaseService {

	@Autowired
	AppInfoDao appInfoDao;
	
	@Autowired
	AppVersionService appVersionService;

	public Page<AppInfo> selectByPage(AppInfoSearchVo searchVo) {
		Page<AppInfo> page = new Page<AppInfo>(searchVo.getPageIndex());
		page.setTotalCount(appInfoDao.selectByPageCount(searchVo));
		page.setDataList(appInfoDao.selectByPage(searchVo,page.getStartRow(),page.getPageSize()));
		return page;
	}

	public boolean addAppInfo(AppInfo appinfo) {
		return appInfoDao.addAppInfo(appinfo) > 0;
	}
	

	public boolean apkexist(String APKName){
		return appInfoDao.apkexist(APKName) > 0;
	}
	//新增版本
	public boolean addAppVersion(AppVersion appVersion){
		boolean b = appVersionService.addAppVersion(appVersion);
		if(b){
			return appInfoDao.updateAppInfoVersionId(appVersion.getAppId(), appVersion.getId(),appVersion.getCreatedBy()) > 0;
		}
		return false;
	}
}
